package com.das.mechanic_base.widget;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.das.mechanic_base.R;
import com.umeng.analytics.MobclickAgent;

/**
 * Created by chensi on 2018/3/9.
 */

public class X3AloneCameraInstructionDialog extends Dialog {
    private Point mScreenPoint = new Point();
    private Activity mRootActivity = null;

    private Button btn_affirm_1;
    private Button btn_affirm;

    /**
     * 没有按钮的提示dialog
     */
    public X3AloneCameraInstructionDialog(Activity arg) {
        super(arg, R.style.pointDialog);
        mRootActivity = arg;
    }

    @SuppressWarnings("deprecation")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setBackgroundDrawable(new BitmapDrawable());
        this.setContentView(R.layout.x3_alone_camera_instruction_dialog);
        initDialogWindow();
        initView();
    }

    void initView() {
        btn_affirm = findViewById(R.id.btn_affirm);
        btn_affirm_1 = findViewById(R.id.btn_affirm_1);

        btn_affirm.setOnClickListener(view -> {
            dismiss();
        });

        btn_affirm_1.setOnClickListener(view -> {
            if (iBtnClick != null){
                iBtnClick.iBtnAffirmClick();
            }
            dismiss();
        });
    }

    IBtnClick iBtnClick;

    public void setiBtnClick(IBtnClick iBtnClick) {
        this.iBtnClick = iBtnClick;
    }
    public interface IBtnClick {
        void iBtnAffirmClick();

    }

    @SuppressWarnings("deprecation")
    private void initDialogWindow() {
        Window dialogWindow = getWindow();
        dialogWindow.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

        WindowManager m = mRootActivity.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用

        try {
            d.getSize(mScreenPoint);
        } catch (NoSuchMethodError ignore) {
            mScreenPoint.x = d.getWidth();
            mScreenPoint.y = d.getHeight();
        }

        WindowManager.LayoutParams p = dialogWindow.getAttributes(); // 获取对话框当前的参数值
        p.width = (int) (mScreenPoint.x * 0.80);    // 宽度设置为屏幕的0.9
        dialogWindow.setAttributes(p);
    }

    @Override
    protected void onStart() {
        super.onStart();
        MobclickAgent.onPageStart("是否全部通过弹窗");
    }

    @Override
    public void dismiss() {
        super.dismiss();
        MobclickAgent.onPageEnd("是否全部通过弹窗");
    }
}

